﻿using System;
using System.IO;
using UnityEngine;

namespace Sizebox.CharacterEditor
{
	// Token: 0x02000257 RID: 599
	public class MaterialPresetsView : BasePresetsView
	{
		// Token: 0x06000CFC RID: 3324 RVA: 0x000688A8 File Offset: 0x00066AA8
		protected override void LoadFile(string filePath)
		{
			if (!this.handleManager.TargetEditor)
			{
				return;
			}
			if (File.Exists(filePath))
			{
				MaterialEdit materialEdit = this.handleManager.TargetEditor.MaterialEdit;
				string json = File.ReadAllText(filePath);
				MaterialDataSet materialData = JsonUtility.FromJson<MaterialDataSet>(json);
				materialEdit.LoadPreset(materialData);
			}
		}

		// Token: 0x06000CFD RID: 3325 RVA: 0x000688FC File Offset: 0x00066AFC
		protected override void SaveFile(string fileName)
		{
			if (!this.handleManager.TargetEditor)
			{
				return;
			}
			MaterialEdit materialEdit = this.handleManager.TargetEditor.MaterialEdit;
			MaterialDataSet materialDataSet = new MaterialDataSet();
			foreach (MaterialWrapper materialWrapper in materialEdit.Materials)
			{
				MaterialData data = materialWrapper.GenerateMaterialData();
				if (data != materialWrapper.DefaultData)
				{
					materialDataSet.Add(data);
				}
			}
			string value = JsonUtility.ToJson(materialDataSet);
			TextWriter textWriter = new StreamWriter(string.Concat(new object[]
			{
				this.folderPath,
				Path.DirectorySeparatorChar,
				fileName,
				this.PRESET_EXTENSION
			}));
			textWriter.Write(value);
			textWriter.Close();
		}
	}
}
